package com.njzxw.fs.commonutil.bean;

import com.njzxw.fs.commonutil.annotation.ValidInsert;
import com.njzxw.fs.commonutil.annotation.ValidUpdate;
import com.njzxw.fs.commonutil.util.DateUtil;
import com.njzxw.fs.commonutil.util.Validator;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.Date;
import java.util.List;
import java.util.logging.SimpleFormatter;

@Setter
@Getter
@ToString
public class BaseBean implements BaseBeanInterface {

    @NotBlank(message = "未选择数据",groups = {CheckId.class})
    public String id;

    @NotEmpty(message = "未选择数据",groups = {CheckIds.class})
    public List<String> ids;

    @ValidInsert
    @NotBlank(message = "数据ID未知",groups = {CheckOperId.class})
    public String oper_id = null;

//    @ValidInsert
    public String oper_date = DateUtil.getToday("yyyy-MM-dd HH:mm:ss");

    @NotBlank(message = "登录已失效或未登录",groups = {CheckAuthority.class})
    public String token;

    /**
     * 排序字段
     */
    public String orderBy;

    public Integer pageNum;

    public Integer pageSize;

    /**
     * 排序字段的名称 一般用于表格加载
     */
    public String orderKey;

    @NotEmpty(message = "文件唯一标识丢失",groups = {CheckResouceIds.class})
    public List<String> resouce_ids;

    @NotEmpty(message = "文件唯一标识丢失",groups = {CheckResouceId.class})
    public String resouce_id;

    /**
     * 访问类型：web后台、小程序、web客户端网页
     */
    public String requset_type;

    /**
     * 排序规则 一般用于表格加载
     */
    public String orderRule;

    public String supper_id;

    @ValidUpdate
    public String update_oper_id;

    public void changeOrderBy(){

        if(!StringUtils.isBlank(this.getOrderKey())){
            this.setOrderBy(this.getOrderKey()+" "+(StringUtils.isBlank(this.getOrderRule())?"":this.getOrderRule()));
        }

    }

    /**
     * 用于组织权限控制使用，在paramsValidation中控制
     */
    private String manage_org_table_name;
    /**
     * 用于组织权限控制使用，在paramsValidation中控制
     */
    private String manage_org_table_name_where;

    /**
     * 版本号
     */
    private String version;

    private String sql;

    private String sql1;

    private String sql2;

    public interface CheckId{}

    public interface CheckIds{}

    public interface CheckAuthority{}

    public interface CheckResouceIds{}

    public interface CheckResouceId{}

    public interface CheckOperId{}

}
